home *** CD-ROM | disk | FTP | other *** search
/ MacTech 1 to 12 / MacTech-vol-1-12.toast / Source / MacTech® Magazine / Volume 06 - 1990 / 06.01 Jan 90 / XCMD Text < prev   
Encoding:
Text File  |  1989-11-13  |  2.4 KB  |  120 lines  |  [TEXT/nX^n]

  1. void    ExtToDouble( ext, dbl )
  2.     extended    *ext;
  3.     double        *dbl;
  4. /******************************
  5. * given the extended IEEE number
  6. * passed in, return its double
  7. * representation
  8. *
  9. ******************************/
  10. {
  11.  
  12. asm{
  13.     move.l    8(A6),-(sp)    ; address of the extended
  14.     move.l    12(A6),-(sp)    ; address of the double
  15.     move.w    #FX2D,-(sp)    ; push the appropriate opword
  16.     _FP68K
  17.     }
  18. }
  19.  
  20. void    DoubleToExt( dbl, ext )
  21.     double        *dbl;
  22.     extended    *ext;
  23. /******************************
  24. * given the double number
  25. * passed in, return its extended
  26. * representation
  27. *
  28. ******************************/
  29. {
  30.  
  31. asm{
  32.     move.l    8(A6),-(sp)    ; address of the double
  33.     move.l    12(A6),-(sp)    ; address of the extended
  34.     move.w    #FD2X,-(sp)    ; push the appropriate opword
  35.     _FP68K
  36.     }
  37. }
  38.  
  39. void    LongToExt( lg, ext )
  40.     long        *lg;
  41.     extended    *ext;
  42. /******************************
  43. * given the long  number
  44. * passed in, return its extended
  45. * representation
  46. *
  47. ******************************/
  48. {
  49.  
  50. asm{
  51.     move.l    8(A6),-(sp)    ; address of the long
  52.     move.l    12(A6),-(sp)    ; address of the extended
  53.     move.w    #FL2X,-(sp)    ; push the appropriate opword
  54.     _FP68K
  55.     }
  56. }
  57.  
  58. void    ExtToLong( ext, theint )
  59.     extended    *ext;
  60.     long        *theint;
  61. /******************************
  62. * given the extended IEEE number
  63. * passed in, return its long word
  64. * representation
  65. *
  66. ******************************/
  67. {
  68. asm{
  69.     move.l    8(A6),-(sp)    ; pointer to the extended
  70.     move.l    12(A6),-(sp)    ; address of the long
  71.     move.w    #FX2L,-(sp)    ; push the appropriate opword
  72.     _FP68K
  73.     }
  74. }
  75.  
  76. void    DoubleToLong( dbl, theint )
  77.     double        *dbl;
  78.     long        *theint;
  79. /******************************
  80. * A simple conversion utility that might be useful
  81. * for debugging at the TMON and MACSBUG level.
  82. ******************************/
  83. {
  84.     extended    temp;
  85.     
  86.     DoubleToExt( dbl, &temp);
  87.     ExtToLong( &temp, theint );
  88. }
  89.  
  90. void     ExtendedToStr( ext, theStr )
  91.     extended    *ext;
  92.     char        *theStr;
  93. /*******************************
  94. * convert an extended to a string
  95. * First convert the number to 
  96. * a decimal record and then convert
  97. * the decimal record to a string.
  98. *
  99. * The Hypercard callback "ExtToStr" does
  100. * this for you.  I've added it here for those
  101. * cases where you can't make a callback
  102. *
  103. * The conversions uses the decimal record 
  104. * structure that's documented in Apple Numerics
  105. * manual.
  106. *******************************/
  107. {
  108.     decform    decrec;
  109.     decimal        decnum;
  110.     
  111.     /*** convert the extended to a decimal ***/
  112.  
  113.     decrec.style = FIXEDDECIMAL;
  114.     decrec.digits= 0;
  115.     num2str( &decrec, *ext, theStr );
  116. }
  117.  
  118. LISTING 1. Some Interesting SANE conversion utilities
  119.